using System;
using System.Collections.Generic;
using System.Text;
using Musicman.Entities;

namespace Musicman.Entities.BusinessEntities
{
    public class SearchFolderCollection : IEnumerable<Searchfolder>, ICollection<Searchfolder>
    {
        private List<Searchfolder> _innerList = new List<Searchfolder>();
        private Dictionary<String, Searchfolder> _innerDictionary = new Dictionary<String, Searchfolder>();

        public List<Searchfolder> InnerList
        {
            get { return _innerList; }
        }


        #region IEnumerable<Searchfolder> Members

        public IEnumerator<Searchfolder> GetEnumerator()
        {
            throw new Exception("The method or operation is not implemented.");
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            throw new Exception("The method or operation is not implemented.");
        }

        #endregion

        #region ICollection<Searchfolder> Members

        public void Add(Searchfolder item)
        {
            if (!Contains(item))
            {
                string key = item.Name.ToLower();
                this._innerList.Add(item);
                this._innerDictionary.Add(key, item);
            }
        }

        public void Clear()
        {
            this._innerList.Clear();
            this._innerDictionary.Clear();
        }

        public bool Contains(Searchfolder item)
        {
            string key = item.Name.ToLower();
            return _innerDictionary.ContainsKey(key);
        }

        public void CopyTo(Searchfolder[] array, int arrayIndex)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public int Count
        {
            get { return _innerList.Count; }
        }

        public bool IsReadOnly
        {
            get { throw new Exception("The method or operation is not implemented."); }
        }

        public bool Remove(Searchfolder item)
        {
            string key = item.Name.ToLower();
            if (_innerDictionary.ContainsKey(key))
            {
                Searchfolder folder = _innerDictionary[key];
                _innerList.Remove(folder);
                _innerDictionary.Remove(key);
                return true;
            }
            return false;
        }

        #endregion

        public Searchfolder this[int index]
        {
            get
            {
                return _innerList[index];
            }
        }

        public Searchfolder this[string key]
        {
            get
            {
                return _innerDictionary[key.ToLower()];
            }
        }
    }
}
